package groovy;

import java.util.Date;

public class CarJ implements Cloneable{
    private Date year;
    private Engine engine;

    public static void main(String[] args) {
        CarJ carJ=new CarJ();
        carJ.setYear(new Date());
        Engine engine=new Engine();
        engine.setType("japan");
        carJ.setEngine(engine);
        CarJ carJ1= (CarJ) carJ.clone();
        carJ.setEngine(engine);
    }
    public Object clone(){
        try {
            CarJ cl= (CarJ) super.clone();
            cl.engine= (Engine) engine.clone();
            return cl;
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return null;
    }

    private static class Engine implements Cloneable{
        private String type;

        @Override
        protected Object clone() throws CloneNotSupportedException {
            return super.clone();
        }

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }
    }

    public Date getYear() {
        return year;
    }

    public void setYear(Date year) {
        this.year = year;
    }

    public Engine getEngine() {
        return engine;
    }

    public void setEngine(Engine engine) {
        this.engine = engine;
    }
}
